package com.efast.cafe.portal.controller.company;

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.cafe.framework.bean.ResultBean;
import com.efast.cafe.framework.controller.AbstractController;
import com.efast.cafe.framework.enums.ResultStatus;
import com.efast.cafe.framework.exception.ServiceException;
import com.efast.cafe.portal.bean.company.PortalCompanyReporttoBean;
import com.efast.cafe.portal.service.company.IPortalCompanyPositionRoleService;

/******************************************************************************
 * @File name   :      PortalCompanyPositionRoleComtroller.java
 *
 * @Author      :      xl
 *
 * @Date        :      2016-8-25
 *
 * @Copyright Notice: 
 * Copyright (c) 2016 Efast Serv. All  Rights Reserved.
 * This software is published under the terms of the Efast Software
 * License version 1.0, a copy of which has been included with this
 * distribution in the LICENSE.txt file.
 * 
 * 
 * ----------------------------------------------------------------------------
 * Date                   Who         Version        Comments
 * 2016-8-25 下午5:26:24        xl     1.0            Initial Version
 *****************************************************************************/
@Controller
@RequestMapping("/frame_center/company")
public class PortalCompanyPositionRoleComtroller extends AbstractController{
	@Autowired
	private IPortalCompanyPositionRoleService portalCompanyPositionRoleService;
	
	

	/**
	 * 获取职位相关的角色
	 * @Date        :      2016-8-26
	 * @param positionId
	 * @return
	 */
	@RequestMapping(value = "/positionrole/multiple")
	public @ResponseBody ResultBean 
	getPositionRoleMultiple(@RequestBody PortalCompanyReporttoBean bean){
		ResultBean result=new ResultBean(true,"");
		Long positionId=Long.parseLong(bean.getPositionId().toString());
		result.setObject(portalCompanyPositionRoleService.getPositionRoleMultiple( positionId));
		return result;
	}
	
	/**
	 * 保存职位相关的角色
	 * @Date        :      2016-8-26
	 * @param positionId
	 * @param roles
	 * @return
	 */
	@RequestMapping(value = "/positionrole/save")
	public @ResponseBody ResultBean savePositionRoleMultiple(@RequestBody PortalCompanyReporttoBean bean){
		ResultBean result=new ResultBean(true,"");
		try {
			Long positionId=Long.parseLong(bean.getPositionId().toString());
			Long [] roles = (Long []) bean.getRoles().toArray(new Long[bean.getRoles().size()]); 
			portalCompanyPositionRoleService.savePositionRoleMultiple(positionId,roles);
		} catch (Exception e) {
			e.printStackTrace();
			result.setSuccess(false);
			if (e instanceof ServiceException) {
				result.setErrorCode(e.getMessage());
			} else {
				result.setErrorCode(ResultStatus.SYS_ERROR.getCode());
			}
		}
		return result;
	}
	
	
	
}
